<template>
    <div>
        <div id="app" v-cloak>
            
            <headers></headers>
        
            <div class="main_con clearfix">
                <div class="left_menu_con clearfix">
                    <h3>用户中心</h3>
                    <ul>
                        <li><a href="user_center_info.html">· 个人信息</a></li>
                        <li><a href="user_center_order.html">· 全部订单</a></li>
                        <li><a href="user_center_site.html" class="active">· 收货地址</a></li>
                        <li><a href="user_center_pass">· 修改密码</a></li>
                    </ul>
                </div>
                <div class="right_content clearfix">
                    <div class="site_top_con">
                        <a @click='isshow=true'>新增收货地址</a>
                        <span>你已创建了<b>2</b>个收货地址，最多可创建<b>20</b>个</span>
                    </div>
                    <div class="site_con" v-for="i in addresslist" :key="i.id">
                        <div class="site_title">
                            <h3>{{i.linkman}} {{i.provice.name}}</h3>
                            <a href="javascript:;" class="edit_icon"></a>
                            <em>默认地址</em>						
                            <span class="del_site">×</span>
                        </div>
                        <ul class="site_list">
                            <li><span>收货人：</span><b>{{i.linkman}}</b></li>
                            <li><span>所在地区：</span><b>{{i.provice.name}}</b></li>
                            <li><span>地址：</span><b>{{i.city.name}}{{i.area.name}}</b></li>
                            <li><span>手机：</span><b>{{i.mobile}}</b></li>
                            <li><span>固定电话：</span><b>{{i.tel}}</b></li>
                            <li><span>电子邮箱：</span><b>{{i.email}}</b></li>
                        </ul>
                        <div class="down_btn">
                            <a href="javascript:;"  class="edit_icon">编辑</a>
                        </div>
                    </div>
                </div>
            </div>
            <footers></footers>
        
            <div class="pop_con" v-show='isshow'>
                <div class="site_con site_pop">
                        <div class="site_pop_title">
                            <h3>新增收货地址</h3>
                            <a href="javascript:;" @click='isshow=false'>×</a>
                        </div>				
                        <form>
                            <div class="form_group">
                                <label>收货人：</label>
                                <input type="text" name="receiver" class="receiver" v-model="form.linkman">
                                <span class="receiver_error">请填写收货人</span>
                            </div>
                            <div class="form_group">
                                <label>所在地区：</label>
                                <select v-model='form.provice' @change='getCity'>
                                    <option  v-for='i in provice' :value='i.id' :key="i.id">{{i.name}}</option>
                                    
                                </select>
                                <select v-model='form.city' @change='getArea'>
                                        <option  v-for='i in city' :value='i.id' :key="i.id">{{i.name}}</option>
                                        
                                    </select>
                                    <select v-model='form.area' >
                                            <option  v-for='i in area' :value='i.id' :key="i.id">{{i.name}}</option>
                                            
                                        </select>
                            </div>
                            <div class="form_group">
                                <label>详细地址：</label>
                                <input type="text" name="place" class="place" v-model="form.address">
                                <span class="place_error">请填写详细地址</span>
                            </div>
                            <div class="form_group">
                                <label>手机：</label>
                                <input type="text" name="mobile" class="mobile" v-model="form.mobile">
                                <span class="mobile_error">手机号有误</span>
                            </div>
                            <div class="form_group">
                                <label>固定电话：</label>
                                <input type="text" name="tel" class="tel" v-model="form.tel">
                                <span class="tel_error">固定电话有误</span>
                            </div>
                            <div class="form_group">
                                <label>邮箱：</label>
                                <input type="text" name="email" class="email" v-model="form.email">
                                <span class="email_error">邮箱格式有误</span>
                            </div>
                            <input type="button" name="" value="新 增" class="info_submit" @click.prevent='add'>
                            <input type="reset" name="" value="取 消" class="info_submit info_reset">
                        </form>
                </div>
                <div class="mask"></div>
            </div>
        
            <div class="pop_con2">
                <div class="confirm_pop">
                        <div class="confirm_pop_title">
                            <h3>确认删除</h3>
                            <a href="javascript:;">×</a>
                        </div>
                        <p>您确认删除当前地址吗？</p>
                        <input type="button" value="确 定" class="confirm_submit" />
                        <input type="button" value="取 消" class="confirm_submit confirm_cancel"  />
                </div>
                <div class="mask"></div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
import Headers from './Headers.vue'
import Footers from './Footers.vue'
export default {
  components: { Headers, Footers },
    data() {
        return {
            isshow:false,
            provice:[],
            city:[],
            area:[],
            form:{
                user:localStorage.getItem('userid'),
                username:localStorage.getItem('username')
                },
            addresslist:[],
        }
    },
    methods: {
        // 跳转修改密码
        toUser_center_pass() {
            this.$router.push({
                name:'user_center_pass'
            })
        },
        // 添加地址
        add() {
            this.axios.post('users/address_manage/', this.form).then(res=>{
                // console.log(res.data)
                if(res.data.code==200){
                    this.isshow=false
                    // this.getAddressList()

                }
            })
        },
        //获取地址
        getAddress(){
            this.axios.get('users/address_manage/?userid='+this.form.user).then(res=>{
                // console.log(res.data)
                if(res.data.code==200){
                    this.addresslist=res.data.list

                }
            })
        },
        // 获取省
        getProvice(){
            console.log(this.form)
            this.axios.get('users/provice_manage/').then(res=>{
                if(res.data.code == 200){
                    this.provice = res.data.list
                }
            })
        },
        //获取市
        getCity(){
            this.axios.get('users/provice_manage/?pid='+this.form.provice).then(res=>{
                if(res.data.code == 200){
                    this.city = res.data.list
                }
            })
        },
        //获取区
        getArea(){
            this.axios.get('users/provice_manage/?pid='+this.form.city).then(res=>{
                if(res.data.code == 200){
                    this.area = res.data.list
                }
            })
        },
    },
    created() {
        this.getProvice()
        this.getAddress()
    }
}
</script>

<style scoped>

</style>
